package com.android.signhelper.presenter;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.android.signhelper.base.BasePresenter;
import com.android.signhelper.bean.SignInfo;


import com.android.signhelper.interfaces.TestContract;
import com.android.signhelper.interfaces.MyCallback;
import com.android.signhelper.model.MainModel;

import java.util.HashMap;
import java.util.Map;


/**
 * Created by ikata on 2018/11/15.
 */

public class TestPresenter extends BasePresenter<TestContract.View> implements TestContract.Presenter{

    private MainModel model;

    public TestPresenter()
    {
        model=new MainModel();
    }

    @Override
    public void sign(String token,SignInfo signInfo) {
        //NullPointerException
        Map<String,String> map= new HashMap<>();
        if (signInfo != null) {
            map.put("devUuid", signInfo.getDevUuid());
            map.put("signId", signInfo.getSignId());
            map.put("bleId", signInfo.getBleId());
        }

        model.sign(token, map,callback);
    }


    @Override
    public void login(String userName, String password) {
        model.login(userName, password, callback);
    }

    @Override
    public void detail(String token, String userName) {
            model.detail(token, callback);
    }
    MyCallback callback= new MyCallback() {
        @Override
        public void onSuccess(@Nullable Bundle bundle) {
            if (getView() != null) {
                getView().showData( bundle.getParcelable("data").toString());
            }
        }
        @Override
        public void onFailed(String msg) {
            if (getView() != null) {
                getView().showToast(msg);
            }
        }
    };
}
